package com.yidu.CashAdministration.service.impl;

import com.yidu.CashAdministration.entity.MoneyAllocateEntity;
import com.yidu.CashAdministration.mapper.MoneyAllocateMapper;
import com.yidu.CashAdministration.service.MoneyAllocateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MoneyAllocateImpl implements MoneyAllocateService {
    @Autowired
    MoneyAllocateMapper moneyAllocateMapper;

    @Override
    public List<MoneyAllocateEntity> moneyAllocateSelect(int page, int limit,MoneyAllocateEntity moneyAllocateEntity) {
        Map map = new HashMap();
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        map.put("moneyAllocate",Splicing(moneyAllocateEntity));
        System.out.println(moneyAllocateEntity+"ilmp"+new MoneyAllocateImpl().Splicing(moneyAllocateEntity));
        List<MoneyAllocateEntity> moneyAllocateEntitiesList = moneyAllocateMapper.moneyAllocateSelect(map);
        return moneyAllocateEntitiesList;
    }



    @Override
    public void moneyAllocateInsert(MoneyAllocateEntity moneyAllocateEntity) {
        moneyAllocateMapper.moneyAllocateInsert(moneyAllocateEntity);
    }

    @Override
    public void moneyAllocateUpdate(MoneyAllocateEntity moneyAllocateEntity) {
        moneyAllocateMapper.moneyAllocateUpdate(moneyAllocateEntity);
    }

    @Override
    public int moneyAllocateDelete(String moneyAllocateId) {
        int i = moneyAllocateMapper.moneyAllocateDelete(moneyAllocateId);
        return i;
    }

    @Override
    public int selectCount(MoneyAllocateEntity moneyAllocateEntity) {
        Map map = new HashMap();
        map.put("allocate",Splicing(moneyAllocateEntity));
        int i = moneyAllocateMapper.selectCount(map);
        System.out.println(i+"网页数量");
        return i;
    }

    public String Splicing(MoneyAllocateEntity moneyAllocateEntity) {
        StringBuffer sqlWhere = new StringBuffer("") ;
        if (moneyAllocateEntity.getAllocateDate()!=null && !moneyAllocateEntity.getAllocateDate().equals("")){
            sqlWhere.append(" and allocateDate = '"+moneyAllocateEntity.getAllocateDate()+"'");
        } if (moneyAllocateEntity.getAllocateType()!=0){
            sqlWhere.append(" and allocateType = '"+moneyAllocateEntity.getAllocateType()+"'");
        } if (moneyAllocateEntity.getAllocateFlow()!=0 ){
            sqlWhere.append(" and allocateFlow = '"+moneyAllocateEntity.getAllocateFlow()+"'");
        }
        System.out.println(sqlWhere+"builber");
        return sqlWhere.toString();
    }
}
